#ifndef __DEBUG__H
#define __DEBUG__H

#include <stdio.h>
#include <syslog.h>
#include <sys/types.h>
#include <unistd.h>

#define HD              "\033["
#define TAIL            "m"
#define FG              "3"
#define BG              "4"

#define DEFUALT         "0"
#define HIGHTLIGHT      "1"
#define UNBLOD          "22"
#define UNDERLINE       "4"
#define FLICKER         "5"

#define DARK            "0"
#define RED             "1"
#define GREEN           "2"
#define YELLOW          "3"
#define BLUE            "4"
#define PURPLE          "5"
#define CYAN            "6"
#define WHITE           "7"
#define RECOVER         HD"0"TAIL

#define STYLE( t, fc, bc )    HD t ";" FG fc ";" BG bc TAIL

#define VERBOSE     0
#define INFO        1
#define DEBUG       2
#define ERROR       3


#define MODULE_COLOR    YELLOW

#define ENABLE_LOG   0
#define DEGUGLEVEL   INFO

#if ENABLE_LOG
#define DEBUG_PRINTF(level, fmt, arg...) do \
        {\
            if ( level >= DEGUGLEVEL ) \
            { \
                syslog(level, "<%d> [%d][%s]--->" fmt, (unsigned int)getpid(),__LINE__, __FUNCTION__, ##arg); \
            } \
        }while(0)
#else
#define DEBUG_PRINTF( level, fmt, arg... ) do \
    {\
        if ( level == ERROR )\
        {\
            printf(STYLE(HIGHTLIGHT,RED,DARK)  "[%s]-[%d]\t" fmt  RECOVER "\n", __FUNCTION__, __LINE__, ##arg);\
        }\
        else if ( level == DEBUG )\
        {\
            printf(STYLE(HIGHTLIGHT,CYAN,DARK)  "[%s]-[%d]\t" fmt  RECOVER "\n", __FUNCTION__, __LINE__, ##arg);\
        }\
        else if ( level == INFO )\
        {\
            printf(STYLE(HIGHTLIGHT,YELLOW,DARK)  "[%s]-[%d]\t" fmt  RECOVER "\n", __FUNCTION__, __LINE__, ##arg);\
        }\
    }while(0)

#endif

#define LOGV(fmt, arg...) DEBUG_PRINTF(INFO,fmt,##arg)
#define LOGD(fmt, arg...) DEBUG_PRINTF(DEBUG,fmt,##arg)
#define LOGI(fmt, arg...) DEBUG_PRINTF(INFO,fmt,##arg)
#define LOGW(fmt, arg...) DEBUG_PRINTF(ERROR,fmt,##arg)
#define LOGE(fmt, arg...) DEBUG_PRINTF(ERROR,fmt,##arg)

#define DEBUG_MODE  1

#endif
